﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PropertyExpression.Common;
using PropertyExpression.ControllableQuery;

namespace ControllableQuery.Demo.SQLite
{
    internal class Program
    {
        private static void Main()
        {
            DB.ConnectionFunc = QExecuter.ConnectionFunc;

            var id = 1;

            NonQuery.New(new {}, "DELETE FROM T1").Execute();

            NonQuery.New(new {
                Id = id, T001 = "qwe3", T002 = "qwe4", T003 = new Option<int>().Param(),
                T004 = new Option<DateTime>().Param(), T005 = DateTime.Now
            }, "@DB.Insert(\"T1\", p)").Execute();

            Assert.AreEqual("qwe3",
                Query<string>.New(new {id}, "SELECT T001 FROM T1 WHERE Id = @id").Result().Single());

            NonQuery.New(new {
                Id = id, T001 = "qwe5", T002 = "qwe4", T003 = 2, T004 = DateTime.Now, T005 = DateTime.Now
            }, "@DB.Update(\"T1\", p)").Execute();

            Assert.AreEqual("qwe5",
                Query<string>.New(new {id}, "SELECT T001 FROM T1 WHERE Id = @id").Result().Single());

            NonQuery.New(new {
                Id = id
            }, "@DB.Delete(\"T1\", p)").Execute();
        }
    }
}
